<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\CoSchoolName;
use App\Models\CoSchool;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;
use Illuminate\Http\Request;

class CoSchoolNameController extends AdminController
{
    protected $title = '楼栋类型管理';

    public function __construct(Request $request)
    {
        $this->school_id = $request->get('school_id',0);
    }
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new CoSchoolName(), function (Grid $grid) {
            $grid->id->sortable();
            $grid->name;
            $grid->status->switch();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
            $grid->disableViewButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CoSchoolName(), function (Show $show) {
            $show->id;
            $show->name;
            $show->status;
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CoSchoolName(), function (Form $form) {
            $form->display('id');
            $form->text('name','楼栋类型名')->required();
            $form->radio('status')->options(['1'=>'启用','0'=>'禁用'])->default(0);
            $form->disableViewButton();
        });
    }
}
